<div id="main-content"> <!-- Main Content Section with everything -->			
	<!-- Page Head -->			
	<form id="search" name='search' method='get' action=''>
		<label>关键词：</label>
		<input type="hidden" name='cat' value='<?php echo $search['cat']?$search['cat']:'';?>' />
		<input class="text-input" id='key' type='text' name='key' value='<?php $key = $search['key']?$search['key']:''; echo $key;?>' />
		<select name="options" id="op">
			<option value="0" <?php echo $options=='0'?'selected':'';?>>库存</option>
			<option value="1" <?php echo $options=='1'?'selected':'';?>>已分配</option>
			<option value="2" <?php echo $options=='2'?'selected':'';?>>报废</option>
		</select> 
		修改时间
		<input class="text-input time" type="text" id="from" name="from" value='<?php $from = $search['from']?$search['from']:''; echo $from;?>' />
		~
		<input class="text-input time" type="text" id="to" name="to" value='<?php $to = $search['to']?$search['to']:''; echo $to;?>' />
		<input class="button" type='submit' value='搜索' />
		<input class='reset button' type='button' value='重置'/>
	</form>
	<div style="margin:20px">
		分类：<a class="button" href="<?php echo base_url();?>parts/?cat=&key=&options=<?php echo $options;?>&from=&to=">ALL</a>
		<?php foreach(parts_options() as $v):?>
			<a class="button" href="<?php echo base_url();?>parts/?cat=<?php echo $v;?>&key=<?php echo $key;?>&options=<?php echo $options;?>&from=<?php echo $from;?>&to=<?php echo $to;?>"><?php echo $v;?></a>
		<?php endforeach;?>
	</div>
	<div class="clear"></div> <!-- End .clear -->
	
	<div class="content-box"><!-- Start Content Box -->
		
		<div class="content-box-header">
			<h3>主机配件管理</h3>
			<div class="clear"></div>
			
		</div> <!-- End .content-box-header -->
		
		<div class="content-box-content">
			
			<div class="tab-content default-tab" id="tab1"> <!-- This is the target div. id must match the href of this div's tab -->						
				<table>
					
					<thead>
						<tr>
						   
						   <th>No.</th>
						   <th>名称</th>
						   <th>品牌</th>
						   <th>价格</th>
						   <th>规格</th>
						   <th>购入时间</th>
						   <?php if($options != 1):?>
						   <th>总数</th>
						   <?php endif;?>
						   <th>备注</th>
						   <th>Options</th>
						   <th>Operation</th>
						</tr>
						
					</thead>
				 
					<tfoot>
						<tr>
							<td colspan="10">										
								<div class="pagination">
									<?php echo $page;?><!-- 分页 -->										
								</div> <!-- End .pagination -->
								<div class="clear"></div>
							</td>
						</tr>
					</tfoot>
				 
					<tbody>
					<?php $i=0; foreach($query as $row):?>
						<tr>									
							<td><?php $i++;echo $i;?></td>
							<td>
								<input type='hidden' value='<?php echo $row['id'];?>'>
								 <?php
									echo $row['name'];
								?>
							</td>
							<td><?php echo $row['brand'];?></td>
							<td><?php echo $row['price'];?></td>
							<td><?php echo $row['condition'];?></td>
							<td><?php echo date('Y-m-d',$row['bought']);?></td>
							<?php if($options != 1):?>
							<td><?php echo $row['num'];?></td>
							<?php endif;?>
							<td><?php echo $row['remark'];?></td>
							<?php if($options==0):?>
							<td>
								<form method='post' action='<?php echo base_url()?>parts/install'>
									<select name='shid' class='staff_options'>											
									<?php foreach(host_staff() as $k=>$v):?>
										<option value='<?php echo $k;?>'><?php echo $v;?></option>
									<?php endforeach;?>
									</select>
									<input type='hidden' value='<?php echo $row['id'];?>' name='id' />
									<input class="button" type='submit' value="装载">
								</form>
							</td>
							<?php elseif($options==1):?>
							<td>
								<div style="float:left;margin-right:25px;">分配到主机：
								<?php $host=host();echo $host[$row['hid']]; $staff=staff_options();echo $row['sid']?'属于员工'.$staff[$row['sid']]:'此时未指定员工';?>
								</div>
								<div style="float:left;margin-right:25px;">
									<form method='post' action='<?php echo base_url()?>parts/unstall'>												
										<input type='hidden' value='<?php echo $row['id'];?>' name='id' />
										<input type='hidden' value='5' name='status' />
										<input class="button" type='submit' value="卸载入库">
									</form>
								</div>
								<div style="float:left;margin-right:25px;">
									<form method='post' action='<?php echo base_url()?>parts/unstall'>												
										<input type='hidden' value='<?php echo $row['id'];?>' name='id' />
										<input type='hidden' value='6' name='status' />
										<input class="button" type='submit' value="卸载报废">
									</form>
								</div>
							</td>
							<?php else:?>
							<td></td>
							<?php endif;?>
							<td>
								<!-- Icons -->
								 <a href="<?php echo base_url()?>parts/modify_parts/<?php echo $row['id'];?>/<?php echo $_SERVER['QUERY_STRING']?>" title="Edit"><img src="<?php echo base_url()?>images/icons/pencil.png" alt="Edit" /></a>
								 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								 <a href="<?php echo base_url()?>parts/del_parts/<?php echo $row['id'];?>" title="Delete" onclick='return del()'><img src="<?php echo base_url()?>images/icons/cross.png" alt="Delete" /></a> 
							</td>
						</tr>
					<?php endforeach;?>	
					</tbody>
					
				</table>
				
			</div> <!-- End #tab1 -->
			

			
		</div> <!-- End .content-box-content -->
		
	</div> <!-- End .content-box -->
	<div class="clear"></div>			
</div> <!-- End #main-content -->	
<script>
$(function(){
	
	$( "#dialog-form" ).dialog({
		autoOpen: false,
		//show: "slide",
		//hide: "explode",
		height: 200,
		width: 350,
		modal: true,
		buttons: {
			Submit: function() {
				$('#log').submit();
			},
			Cancel: function() {
				$( this ).dialog( "close" );
			}
		},
		close: function() {
			allFields.val( "" ).removeClass( "ui-state-error" );
		}
	});

	$( ".create-user" ).dblclick(function() {
		str =$(this).text();
		id = $(this).find('input').val();
		$("#rid").val(id);
		$("#remark").val(str);
		$( "#dialog-form" ).dialog( "open" );
	});
	//time
	var dates = $( "#from, #to" ).datepicker({
		defaultDate: "+1w",
		changeMonth: true,
		numberOfMonths: 3,
		dateFormat: 'yy-mm-dd',
		onSelect: function( selectedDate ) {
			var option = this.id == "from" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dates.not( this ).datepicker( "option", option, date );
		}
	});
	
	$("#op").change(function(){
		$("#search").submit();
	});
})
</script>